1. /* sdfddcmp.cpp by K.Tsuru */
  2. // function ID = 320 DRADIX
  3. /********************************************************
  4. SDouble class
  5. compare |m| and |n| within CurrentMaxSize()
  6. |m| > |n| return 1
  7. |m| == |n| return 0
  8. |m| < |n| return -1
  9. It regards 0.3141592653589 == 0.314159(CurrentMaxSize()).
  10. *********************************************************/
  11. #ifndef SN_H
  12. #include "sn.h"
  13. #endif
  14. int DDCompare(const SDouble& m, const SDouble& n){
  15. // m = 0 || n = 0
  16. if(!m.Sign(320) || !n.Sign(320)) return abs(m.Sign()) - abs(n.Sign());
  17. if(&m == &n) return 0; // same object
  18. if(m.Type() != n.Type()) m.SetError(m.RADIX_ERR, "DDCompare", 320);
  19. //different in exponent of the standard form
  20. if( m.NetRdxExp() != n.NetRdxExp() ) return ( m.NetRdxExp() > n.NetRdxExp() ) ? 1 : -1;
  21. //here same in NetRdxExp()
  22. //Last() < CurrentMaxSize()
  23. int mf = (int)m.First(), ml = (int)m.Last();
  24. int nf = (int)n.First(), nl = (int)n.Last();
  25. SDouble temp;
  26. const fType* mv;
  27. const fType* nv;
  28. /***************************************************
  29. In the fixed point mode it may be diffrent in rdxExp.
  30. ****************************************************/
  31. //adjust the position of figures
  32. if(mf < nf){
  33. mv = m.ReadFigures();
  34. //shift n to upper
  35. temp = n; temp.ShiftArray(mf - nf);
  36. nv = temp.ReadFigures(); nl = (int)temp.Last();
  37. } else if(mf > nf){
  38. nv = n.ReadFigures();
  39. //shift m to upper
  40. temp = m; temp.ShiftArray(-mf + nf);
  41. mv = temp.ReadFigures(); ml = (int)temp.Last();
  42. } else {
  43. //Almost m.rdxExp == n.rdxExp and comes here.
  44. mv = m.ReadFigures(); nv = n.ReadFigures();
  45. }
  46. //Compare from the highest figure.
  47. //It is same in the top position of figures. ml, nl = figures-1
  48. //It cannot assert that larger figures has greater value.
  49. //example :0.0002*D^1 > 0.0001 999999.... *D^1
  50. int c = 0;
  51. int cf = min(mf, nf), cl = min(ml, nl); //range of comparison
  52. register int i;
  53. for(i = cf; i <= cl; i++){
  54. if( mv[i] != nv[i] ){
  55. c = (mv[i] > nv[i]) ? 1 : -1; break;
  56. }
  57. }
  58. if(c) return c;
  59. if( ml == nl ) return 0; //same figures
  60. return ml > nl ? 1 : -1; //larger figures is greater 0.21 > 0.2
  61. }

sdfddcmp.cpp : last modifiled at 2017/03/13 14:31:58(2,153 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).